package com.kma.ncpractice2013.dao;

import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 *
 * @author Illyas
 */
public final class Connector
{
	private static DataSource dataSource;

    private static JdbcTemplate template;
    static
    {
	    oracle.jdbc.pool.OracleDataSource ds = null;
	    try
	    {
		    ds = new oracle.jdbc.pool.OracleDataSource();
	    } catch (SQLException e)
	    {
		    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
	    }


	    try {
		   // jdbc:oracle:thin:[user/password]@//<host><:port>/<service>


		    ds.setURL("jdbc:oracle:thin:viktor/1234asdf@//aa1rdvvf382d5pc.cjh5wszpslx2.us-west-2.rds.amazonaws.com:1521/EBDB");

		    ds.setDriverType("oracle.jdbc.driver.OracleDriver");
		    dataSource = ds;
	    }
	    catch (Exception e)
	    {
		    e.printStackTrace();
	    }
        resetJDBCTemplate();
    }


    public static void resetJDBCTemplate()
    {
	    //ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");


	   /* Context context = null;
	    try
	    {
		    context = new InitialContext();
		    dataSource = (DataSource)context.lookup("jdbc/security");
	    } catch (NamingException e)
	    {
		    e.printStackTrace();
        }
	    template = new JdbcTemplate(dataSource);*/





	    template = new JdbcTemplate(dataSource);

    }
    public static JdbcTemplate getJDBCTemplate()
    {
        return template;
    }

	public static DataSource getDataSource()
	{
		return dataSource;
	}
}
